
/*   
     Table 6
      as originally appeared on the paper
     aged 40-49
  
     file table6_0.sas
       in /home/aleon/project0/programs

     last revised 02-29-2000
*/


options ls=78 compress=yes;

libname raw  '/bbkinghome/sschaner/Angrist Work/Web Papers/AcemogluAngrist_2000/v9data';
libname leon '/bbkinghome/sschaner/Angrist Work/Web Papers/AcemogluAngrist_2000/v9data';

filename moulton3 '/bbkinghome/sschaner/Angrist Work/Web Papers/AcemogluAngrist_2000/SAS programs/moulton3.sas';

data test; set raw.three;

data two; 
set raw.impute3;

***  creating the CSL instruments ****;
**************************************;

length bplg yearat14 enrolage drop_age req_sch work_age work_sch ca cl 3;

yearat14=year*1;
bplg=birthpl; 

if minexpt='NR' or minexpt='NR(?)' then minexpt='0';

if minawork='NR' or minawork='NR(?)' then minawork='0';
if minework='NR' or minework='NR(?)' then minework='0';


* if max='NR' then max='0';
* if min='NR' then min='0';

* enrolage=min*1;
* drop_age=max*1;
req_sch=minexpt*1;
work_age=minawork*1;
work_sch=minework*1;

if ((max='NR') or (min='NR')) then ca=max(0, req_sch);
if ((max ne 'NR') and (min ne 'NR')) then do;
 enrolage=min*1;
 drop_age=max*1;
 ca=max(drop_age-enrolage, req_sch);
end;

if min='NR' then cl=max(0, work_sch);
if (min ne 'NR') then do;
 enrolage=min*1;
 drop_age=max*1;
 cl=max(work_age-enrolage, work_sch);
end;


*length bplg yearat14 enrolage drop_age req_sch work_age work_sch min max minexpt minawork minework ca cl 3;



***  constructing Compulsory-Attendance and Child-Labor-laws instruments **;

* if ca<8 then ca=8;
* ca8=(ca=8);


ca8=(ca<=8);
ca9=(ca=9);
ca10=(ca=10);
ca11=(ca>=11);

cl6=(cl<=6);
cl7=(cl=7);
cl8=(cl=8);
cl9=(cl>=9);

*** interaction terms *****************************;

ca9a=ca9*cl7; ca9b=ca9*cl8; ca9c=ca9*cl9;
ca10a=ca10*cl7; ca10b=ca10*cl8; ca10c=ca10*cl9;
ca11a=ca11*cl7; ca11b=ca11*cl8; ca11c=ca11*cl9;

***************************************************;

keep bplg yearat14 enrolage drop_age req_sch work_age work_sch min max minexpt minawork minework ca cl ca8-ca11 cl6-cl9 ca9a ca9b ca9c ca10a ca10b ca10c ca11a ca11b ca11c; 

***************************************************;
run;

proc sort data=two; by bplg yearat14;
run;

data one; set raw.three (keep = birthqtr bplg statefip educ99 gradcap slwt year yearat14 havecsl lnwkwage age);

 if lnwkwage ne .;  
 if (26<=age<=50); 

proc sort data=one; by bplg yearat14;


data leon.cslin;
 merge one two;
 by bplg yearat14;

proc datasets; delete one; delete two;

data leon.step1; set leon.cslin;

***  creating qob dummies ***********************************;

qtr1=(birthqtr=1); qtr2=(birthqtr=2); qtr3=(birthqtr=3);


***  creating census-year dummies ***************************;

year60=(year=96); year70=(year=97); year80=(year=98); year90=(year=99);

***  creating year-of-birth dummies **************************;

if year=98 then do;
 if birthqtr=1 then yob=1980-age;
 else if birthqtr>1 then yob=1980-age-1;
 end;

if year=97 then do;
 if birthqtr=1 then yob=1970-age;
 else if birthqtr>1 then yob=1970-age-1;
 end;

if year=96 then do;
 if birthqtr=1 then yob=1960-age;
 else if birthqtr>1 then yob=1960-age-1;
 end;

if year=99 then yob=1990-age-1;

if year=95 then yob=1950-age-1;


array yobs(45) yob10-yob54;
do j=1 to 45;
 index=1909+j;
 yobs(j)=(yob=index);
end;



if ( (year=98 and (1930<=yob<=1939)) 
   or (year=97 and (1920<=yob<=1929)) 
   or (year=96 and (1910<=yob<=1919)) ) then qobsampl=1;

if ( (year=98 and (1930<=yob<=1944))
   or (year=97 and (1920<=yob<=1934))
   or (year=96 and (1910<=yob<=1924)) ) then cslsampl=1;


if ( (year=99 and (1940<=yob<=1949))
   or (year=98 and (1930<=yob<=1939))
   or (year=97 and (1920<=yob<=1929))
   or (year=96 and (1910<=yob<=1919))
   or (year=95 and (1900<=yob<=1909)) ) then newsampl=1;


clusid = ((year-95)*100) + statefip;


**** construct new individual schooling variable which ***********;
**** uses imputation for 1990 individuals a-la-Park'94 ***********;

if year=99 then do;
if (1<=educ99<=3) then gradca99=.32;
else if educ99=4 then gradca99=3.19;
else if educ99=5 then gradca99=7.24;
else if educ99=6 then gradca99=8.97;
else if educ99=7 then gradca99=9.92;
else if educ99=8 then gradca99=10.86;
else if educ99=9 then gradca99=11.58;
else if educ99=10 then gradca99=11.99;
else if educ99=11 then gradca99=13.48;
else if (12<=educ99<=13) then gradca99=14.23;
else if educ99=14 then gradca99=16.17;
else if (educ99>=15) then gradca99=17;
end;

else gradca99=gradcap;

***  constructing the age dummies *****************************************;

array aged(25) aged25-aged49;
do k=1 to 25;
* roughage=year-yob-39;
* aged(k)=(roughage=k);
aged(k)=(age=24+k);
end;


***  constructing the 55 state-of-birth and state-of-residence dummies ****;

array sob(55) sob1-sob55; array sor(55) sor1-sor55;
do n=1 to 55;
 sob(n)=(bplg=n);
 sor(n)=(statefip=n);
end;

***  constructing the experience variable ***************;

exp=((age-gradca99)-6);




length sob1-sob55 sor1-sor55 aged25-aged49 qtr1-qtr3
       year60 year70 year80 year90 yob10-yob54 
       qobsampl cslsampl newsampl exp 3;


proc sort data=leon.step1;
 by year statefip;


**** merge on new average schooling variable which does ****;
**** include 1990 imputed values a-la-Park'94 **************;

data four; set raw.average4;
 keep year statefip wtcap990 wtcap;

proc sort data=four;
 by year statefip;


data leon.defin; 
 merge leon.step1 four;
 by year statefip;

proc datasets; delete four;
proc datasets library=leon; delete step1;

proc sort data=leon.defin; by clusid;


data leon.defin2; set leon.defin;


***  restricting sample to males aged 40-49 ****;


if (40<=age<=50);
if lnwkwage ne .;


if 96<=year<=98;
if (havecsl=1 and newsampl=1);


***  constructing the 30 quarter-of-birth/year-of-birth dummies ***********;

qob401 = qtr1 * ((yob10=1) or (yob20=1) or (yob30=1));
qob402 = qtr2 * ((yob10=1) or (yob20=1) or (yob30=1));
qob403 = qtr3 * ((yob10=1) or (yob20=1) or (yob30=1));
qob411 = qtr1 * ((yob11=1) or (yob21=1) or (yob31=1));
qob412 = qtr2 * ((yob11=1) or (yob21=1) or (yob31=1));
qob413 = qtr3 * ((yob11=1) or (yob21=1) or (yob31=1));
qob421 = qtr1 * ((yob12=1) or (yob22=1) or (yob32=1));
qob422 = qtr2 * ((yob12=1) or (yob22=1) or (yob32=1));
qob423 = qtr3 * ((yob12=1) or (yob22=1) or (yob32=1));
qob431 = qtr1 * ((yob13=1) or (yob23=1) or (yob33=1));
qob432 = qtr2 * ((yob13=1) or (yob23=1) or (yob33=1));
qob433 = qtr3 * ((yob13=1) or (yob23=1) or (yob33=1));
qob441 = qtr1 * ((yob14=1) or (yob24=1) or (yob34=1));
qob442 = qtr2 * ((yob14=1) or (yob24=1) or (yob34=1));
qob443 = qtr3 * ((yob14=1) or (yob24=1) or (yob34=1));
qob451 = qtr1 * ((yob15=1) or (yob25=1) or (yob35=1));
qob452 = qtr2 * ((yob15=1) or (yob25=1) or (yob35=1));
qob453 = qtr3 * ((yob15=1) or (yob25=1) or (yob35=1));
qob461 = qtr1 * ((yob16=1) or (yob26=1) or (yob36=1));
qob462 = qtr2 * ((yob16=1) or (yob26=1) or (yob36=1));
qob463 = qtr3 * ((yob16=1) or (yob26=1) or (yob36=1));
qob471 = qtr1 * ((yob17=1) or (yob27=1) or (yob37=1));
qob472 = qtr2 * ((yob17=1) or (yob27=1) or (yob37=1));
qob473 = qtr3 * ((yob17=1) or (yob27=1) or (yob37=1));
qob481 = qtr1 * ((yob18=1) or (yob28=1) or (yob38=1));
qob482 = qtr2 * ((yob18=1) or (yob28=1) or (yob38=1));
qob483 = qtr3 * ((yob18=1) or (yob28=1) or (yob38=1));
qob491 = qtr1 * ((yob19=1) or (yob29=1) or (yob39=1));
qob492 = qtr2 * ((yob19=1) or (yob29=1) or (yob39=1));
qob493 = qtr3 * ((yob19=1) or (yob29=1) or (yob39=1));


*** defining the macros ***********************************;


%macro qobset; qob401 qob402 qob403 qob411 qob412 qob413 qob421 qob422 qob423 qob431 qob432 qob433 qob441 qob442 qob443 qob451 qob452 qob453 qob461 qob462 qob463 qob471 qob472 qob473 qob481 qob482 qob483 qob491 qob492 qob493 %mend;

length %qobset 3;

%macro controls; yob10-yob38 /* aged40-aged48 */ sor1 sor4-sor6 sor8-sor13 sor16-sor42 sor44-sor51 sor53-sor55 sob1 sob4-sob6 sob8-sob13 sob16-sob42 sob44-sob51 sob53-sob55 %mend;

%macro caset; ca9 ca10 ca11 %mend;
%macro clset; cl7 cl8 cl9 %mend;
%macro interacs; ca9a ca9b ca9c ca10a ca10b ca10c ca11a ca11b ca11c %mend;

length %caset %clset %interacs 3;

data ten; set leon.defin2;
run;

**************************************************;
***   Table 6  Column 1 **************************;
**************************************************;

proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 1';
title2 'CLs on average schooling';
model wtcap990 = %clset %controls %qobset;
output out=test2c p=p_wtcap r=v_ij;

data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=159;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


*proc sort data=ten;
*by clusid;

proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 1';



*** Estimation with QOB and CL instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
 title '2sls, QOB & CL estimates';
 title2 'Table 6 Column 1';
 endogenous lnwkwage gradca99 wtcap990;
 instruments %controls %qobset %clset;
 model lnwkwage = gradca99 wtcap990 %controls;
 output r=v_ij;

 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

proc reg data=ten; weight slwt;
model gradca99 = %controls %qobset %clset /noprint;
output out=test2b p=p_gracap;

 data test2c; set test2c (keep=p_wtcap);
 data test2d; merge test2b test2c;

proc datasets; delete test2b test2c;

proc reg data=test2d; weight slwt;
model p_gracap = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2d; weight slwt;
model p_wtcap = %controls p_gracap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2d;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 1';
run;


**************************************************;
***   Table 6  Column 2 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 2';
title2 'CAs on average schooling';
model wtcap990 = %caset %controls %qobset;
output out=test2c p=p_wtcap r=v_ij;

data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=159;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=158;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


*proc sort data=ten;
*by clusid;

proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 sizeds;
 drop dummy _type_;
 
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_ca10= sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_ca11= sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 2';


*** Estimation with QOB and CA instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
 title '2sls, QOB & CA estimates';
 title2 'Table 6 Column 2';
 endogenous lnwkwage gradca99 wtcap990;
 instruments %controls %qobset %caset;
 model lnwkwage = gradca99 wtcap990 %controls;
 output r=v_ij;

 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

proc reg data=ten; weight slwt;
model gradca99 = %controls %qobset %caset /noprint;
output out=test2b p=p_gracap;

 data test2c; set test2c (keep=p_wtcap);
 data test2d; merge test2b test2c;

proc datasets; delete test2b test2c;

proc reg data=test2d; weight slwt;
model p_gracap = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2d; weight slwt;
model p_wtcap = %controls p_gracap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2d;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 2';
run;


**************************************************;
***   Table 6  Column 3 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 3';
title2 'CAs and CLs on average schooling';
model wtcap990 = %clset %caset %controls %qobset;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=162;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %caset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %caset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %caset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %clset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=5;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %clset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=6;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %clset %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=7;
 %let k=161;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 ds5 ds6 ds7 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho5*rho1 ) );
mou_ca10= sqrt(1 + (((v/m) + (m-1))*rho6*rho1 ) );
mou_ca11= sqrt(1 + (((v/m) + (m-1))*rho7*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 3';


*** Estimation with QOB and CL & CA instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt; 
title '2sls, CA and CL estimates --aged 40-49 -- gradca endogenous --';
 title2 'Table 6 -- Column 3';
endogenous lnwkwage wtcap990 gradca99;
instruments %controls %clset %caset %qobset;
model lnwkwage = gradca99 wtcap990 %controls;
output r=v_ij;

 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

proc reg data=ten; weight slwt;
model gradca99 = %controls %qobset %clset %caset /noprint;
output out=test2b p=p_gracap;

 data test2c; set test2c (keep=p_wtcap);
 data test2d; merge test2b test2c;

proc reg data=test2d; weight slwt;
model p_gracap = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2d; weight slwt;
model p_wtcap = %controls p_gracap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2d;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 3';



**************************************************;
***   Table 6  Column 4 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 4';
title2 'CAs CLs and interactions on average schooling ';
model wtcap990 = %clset %caset %interacs %controls %qobset;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=171;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %caset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %caset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %caset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %clset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=5;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %clset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=6;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %clset %interacs %controls %qobset /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=7;
 %let k=170;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 ds5 ds6 ds7 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho5*rho1 ) );
mou_ca10= sqrt(1 + (((v/m) + (m-1))*rho6*rho1 ) );
mou_ca11= sqrt(1 + (((v/m) + (m-1))*rho7*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 4';


*** Estimation with QOB and CL CA & interactions instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
title '2sls, CA CL and int estimates --aged 40-49 --gradca endogenous --';
 title2 'Table 6 -- Column 4';
endogenous lnwkwage wtcap990 gradca99;
instruments %clset %caset %interacs %qobset %controls;
model lnwkwage = gradca99 wtcap990 %controls;
output r=v_ij;


 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

proc reg data=ten; weight slwt;
model gradca99 = %controls %qobset %clset %caset /noprint;
output out=test2b p=p_gracap;

 data test2c; set test2c (keep=p_wtcap);
 data test2d; merge test2b test2c;

proc reg data=test2d; weight slwt;
model p_gracap = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2d; weight slwt;
model p_wtcap = %controls p_gracap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2d;

data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 4';



*************************************************************;
***  Second half of Table 6 *********************************;
*** individual schooling treated as exogenous ***************;
*************************************************************;


**************************************************;
***   Table 6  Column 5 **************************;
**************************************************;

proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 5';
title2 'CLs on average schooling';
model wtcap990 = %clset %controls gradca99;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=130;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);


 %let step=4;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 5';


*** Estimation with CL instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
 title '2sls, CL estimates --aged 40-49 -- gradca exogenous --';
 title2 'Table 6 -- Column 5';
 endogenous lnwkwage wtcap990;
 instruments %controls %clset gradca99;
 model lnwkwage = gradca99 wtcap990 %controls;
 output r=v_ij;

 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

 data test2c; set test2c (drop=v_ij);

proc reg data=test2c; weight slwt;
model p_wtcap = %controls gradca99 /noprint;
output out=test2 r=v_ij;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2c; weight slwt;
model gradca99 = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2c;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;



proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 5';


**************************************************;
***   Table 6  Column 6 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 6';
title2 'CAs on average schooling';
model wtcap990 = %caset %controls gradca99;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=130;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);


 %let step=4;
 %let k=129;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 sizeds;
 drop dummy _type_;
 
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_ca10 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_ca11 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 6';


*** Estimation with CA instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
 title '2sls, CA estimates --aged 40-49 -- gradca exogenous --';
 title2 'Table 6 -- Column 5';
 endogenous lnwkwage wtcap990;
 instruments %controls %caset gradca99;
 model lnwkwage = gradca99 wtcap990 %controls;
 output r=v_ij;

 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

 data test2c; set test2c (drop=v_ij);

proc reg data=test2c; weight slwt;
model p_wtcap = %controls gradca99 /noprint;
output out=test2 r=v_ij;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2c; weight slwt;
model gradca99 = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2c;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;



proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 6';


**************************************************;
***   Table 6  Column 7 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 7';
title2 'CAs and CLs on average schooling';
model wtcap990 = %clset %caset %controls gradca99;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=133;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %caset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %caset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %caset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %clset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=5;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %clset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=6;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %clset %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=7;
 %let k=132;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 ds5 ds6 ds7 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho5*rho1 ) );
mou_ca10= sqrt(1 + (((v/m) + (m-1))*rho6*rho1 ) );
mou_ca11= sqrt(1 + (((v/m) + (m-1))*rho7*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 7';


*** Estimation with CL & CA instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt; 
title '2sls, CA and CL estimates --aged 40-49 -- gradca exogenous --';
 title2 'Table 6 -- Column 7';
endogenous lnwkwage wtcap990;
instruments %controls %clset %caset gradca99;
model lnwkwage = gradca99 wtcap990 %controls;
output r=v_ij;


 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

 data test2c; set test2c (drop=v_ij);

proc reg data=test2c; weight slwt;
model p_wtcap = %controls gradca99 /noprint;
output out=test2 r=v_ij;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2c; weight slwt;
model gradca99 = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2c;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;



proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 7';


**************************************************;
***   Table 6  Column 8 **************************;
**************************************************;


proc reg data=ten; weight slwt;
title 'Table 6 -- aged40-49 -- Column 8';
title2 'CAs and CLs and interactions on average schooling';
model wtcap990 = %clset %caset %interacs %controls gradca99;
output out=test2c p=p_wtcap r=v_ij;


data test2; set test2c;
v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=140;
 %let randvar=clusid;
 %include moulton3;


proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl7 = cl8 cl9 %caset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl8 = cl7 cl9 %caset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model cl9 = cl7 cl8 %caset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=4;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc reg data=ten; weight slwt;
model ca9 = ca10 ca11 %clset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=5;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca10 = ca9 ca11 %clset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=6;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;

proc reg data=ten; weight slwt;
model ca11 = ca9 ca10 %clset %interacs %controls gradca99 /noprint;
output out=test2 r=v_ij;

data test2; set test2; v_ij=v_ij*sqrt(slwt);

 %let step=7;
 %let k=139;
 %let randvar=clusid;
 %include moulton3;

proc datasets; delete test2;


proc summary data=ten;
by clusid;
var gradca99;
output out=sizeds n=size;

proc summary data=sizeds;
var size;
output out=sizeds mean=m var=v;

proc print data=sizeds;

data calc;
 merge ds1 ds2 ds3 ds4 ds5 ds6 ds7 sizeds;
 drop dummy _type_;
 
mou_cl7 = sqrt(1 + (((v/m) + (m-1))*rho2*rho1 ) );
mou_cl8 = sqrt(1 + (((v/m) + (m-1))*rho3*rho1 ) );
mou_cl9 = sqrt(1 + (((v/m) + (m-1))*rho4*rho1 ) );
mou_ca9 = sqrt(1 + (((v/m) + (m-1))*rho5*rho1 ) );
mou_ca10= sqrt(1 + (((v/m) + (m-1))*rho6*rho1 ) );
mou_ca11= sqrt(1 + (((v/m) + (m-1))*rho7*rho1 ) );

proc print;
title 'Moulton factors for standard errors in Table 6, column 8';


*** Estimation with CL CA & interactions instruments *******;

proc syslin 2sls out=test2 data=ten; weight slwt;
title '2sls, CA CL and int estimates --aged 40-49 -- gradca exogenous --';
 title2 'Table 6 -- Column 8';
endogenous lnwkwage wtcap990;
instruments %controls %clset %caset %interacs gradca99;
model lnwkwage = gradca99 wtcap990 %controls;
output r=v_ij;


 data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=1;
 %let k=128;
 %let randvar=clusid;
 %include moulton3;

 proc datasets; delete test2;

 data test2c; set test2c (drop=v_ij);

proc reg data=test2c; weight slwt;
model p_wtcap = %controls gradca99 /noprint;
output out=test2 r=v_ij;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=3;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;


proc reg data=test2c; weight slwt;
model gradca99 = %controls p_wtcap /noprint;
output out=test2 r=v_ij;

proc datasets; delete test2c;


data test2; set test2;
 v_ij=v_ij*sqrt(slwt);

 %let step=2;
 %let k=127;
 %let randvar=clusid;
 %include moulton3;



proc summary data=ten;
 by clusid;
 var lnwkwage;
 output out=sizeds n=size;

proc summary data=sizeds;
 var size;
 output out=sizeds mean=m var=v;


data calc;
 merge ds1 ds2 ds3 sizeds;
 drop dummy _type_;
 
 mou_grac=sqrt(1 + ( ((v/m)+(m-1))*rho2*rho1 ) );
 mou_wcap=sqrt(1 + ( ((v/m)+(m-1))*rho3*rho1 ) );

proc print;
title 'moulton factor for Table 6 col 8';


run;

endsas;
